package com.yst.gateway.monitor.common.validator.annotations;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 自定义枚举表属性校验实现类
 * @author sheungxin
 *
 */
public class EnumValueValidator implements ConstraintValidator<EnumValue, String>{

	private String[] values;
	
	@Override
	public void initialize(EnumValue constraintAnnotation) {
		values=constraintAnnotation.value();
	}

	@Override
	public boolean isValid(String value, ConstraintValidatorContext context) {
		boolean flag=false;
		if(value!=null){
			for(String v:values){
				if(value.equals(v)){
					flag=true;
				}
			}
		}else{
			flag=true;
		}
		return flag;
	}

}
